package com.example.springaop.Aspect;


import com.example.springaop.Controller.UserController;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserAspect {
    @Autowired
    private UserController controller;

    private long befortime;
    private long aftertime;

    @Pointcut("execution(* com.example.springaop.Controller.UserController.* (..))")
    public void pointcut(){}

    @Before("pointcut()")
    public void Before(){
        System.out.println("执行了前置方法");
        befortime=System.currentTimeMillis();
    }

    @After("pointcut()")
    public void After(){
        System.out.println("执行了后置方法");
        aftertime=System.currentTimeMillis();
        System.out.println("方法执行耗时"+(aftertime-befortime)+"ms");
    }
}
